﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Model.Common;
using Jzy.Core.Utility;
using Jzy.Core.Common;
using Jzy.Core.Log.Exceptions;
using ECommerce.BLL.Member;
using ECommerce.Model.Member;
using Jzy.Core.Common.Web;

namespace ECommerce.Web.Site
{
    public partial class Register : System.Web.UI.Page
    {
        private MemberBaseBO Member
        {
            get
            {
                return MemberBaseBO.Instance<MemberBaseBO>();
            }
        }

      
        protected void Page_Load(object sender, EventArgs e)
        {

            
        }

        

        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {
                string loginName = LoginName.Text.Trim();
                if (Member.ExistField("LoginName", loginName, null))
                {
                    JSUtil.Alert("用户名已存在");
                }
                else
                {

                    MemberBaseInfo info = new MemberBaseInfo();
                    EntityUtil.SetEntity(pnlMain, info);                    
                    info.InputTime = DateTime.Now;
                    info.Password = Member.Encript(info);
                    info.State = (int)MemberState.启用;
                    info.Level = (int)MemberLevel.普通会员;
                    Member.Save(info);

                    Member.SetSession(loginName);

                    string script = "alert('注册成功');top.location.href=top.location.href;top.delDivFrm();";
                    JSUtil.ResponseJS(script);
                }
            
            }
            catch (Exception ex)
            {
                ExceptionLogBO.Save(ex);
                JSUtil.Alert("注册失败");
                
            }
        }

    }
}